<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="button" value="留言" id="btn">
    <table>
        <thead>
            <tr style="border-bottom: red;">
                <th>lD</th>
                <th>标题</th>
                <th>留言人</th>
                <th>内容</th>
                <th>时间</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody id="d1">
            <tr>
                <td>3</td>
                <td>本周考试</td>
                <td>浩</td>
                <td>小考试</td>
                <td>2022-3-25-17:00:00</td>
                <td><button style="width: 100px; background: crimson;">删除</button></td>
            </tr>
            <tr>
                <td>4</td>
                <td>下周考试</td>
                <td>浩1</td>
                <td>小考试2</td>
                <td>2022-3-25-17:00:11</td>
                <td><button style="width: 100px; background: crimson;">删除</button></td>
            </tr>
        </tbody>
    </table>

    <div id="a1">
        <h1>发布留言</h1>
        <hr>
        <p>留言标题:</p><br>
        <input type="text"><br>
        <p>留言人:</p><br>
        <input type="text"><br>
        <p>留言内容:</p><br>
        <input type="text"><br>
        <hr>
        <button id="guan">关闭</button>
        <button id="fa">发布</button>
    </div>
    
    <style>
        div{
            display: none;
        }
    </style>
</body>
<script>

    window.onload = function () {
            var a = document.getElementById('d1')
            var b = new XMLHttpRequest()
            b.onreadystatechange = function () {
                if (b.readyState==4 && b. status == 200){
                    var cc=JSON.parse(b.responseText)
                    var str=""

                    console.log(111);
                    for(let d in cc.data){
                        console.log(cc.data)
                     str += `<tr>
                     <th>${cc.data[d].id}</th>
                     <th>${cc.data[d].title}</th>
                     <th>${cc.data[d].name}</th>
                     <th>${cc.data[d].content}</th>
                     <th>${cc.data[d].updated_at}</th>
                     
                     </tr>`
                    }
                    a.innerHTML = str 
                }
         
            }
            b.open('GET', 'https://liu.zzgoodqc.cn/lyb', true)
            b.send()
    }
</script>
</html>
